<!DOCTYPE html>
<html lang="zh-CN">
<head>
    //@ include("/inc/head.html"){}
    <title>资源信息</title>
</head>
<body>

//@ include("/shiro/top.html"){}

<div class="container">

    //@ if(isNotEmpty(errMsg)){
    <div class="alert alert-danger" role="alert">${errMsg!}</div>
    //@ }

    <ol class="breadcrumb">
        <li><a href="${ctxPath}/shiro/main">权限管理</a></li>
        <li><a href="${ctxPath}/shiro/resource/list">资源管理</a></li>
        <li class="active">
            //@ if(action=='insert'){print('新增资源');}else{print('修改资源');}
        </li>
    </ol>

    <form class="form-horizontal" method="post" action="${ctxPath}/shiro/resource/${action}">
        <div class="form-group" style="display: none;">
            <label class="col-sm-2 control-label">ID</label>
            <div class="col-sm-10">
                <input class="form-control" name="resource.id" value="${resource.id!}" placeholder="ID" readonly
                       required/>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">父资源</label>
            <div class="col-sm-10">
                <select class="form-control" name="resource.pid" multiple>
                    //@ for(r in resources){
                    <option value="${r.id}">
                        //@ var i=r.levels;while(i-->0){print('　');}
                        ${r.name}
                    </option>
                    //@ }
                </select>
                <script>
                    $('select[name="resource.pid"]').select2({
                        maximumSelectionLength: 1
                    });
                    $('select[name="resource.pid"]').on('select2:selecting', function (evt) {
                        if (evt.params.args.data.id == '${resource.id!}') {
                            toastr.error('父级资源不可以选择自己！');
                            return false;
                        }
                    });
                    $('select[name="resource.pid"]').val('${resource.pid!}').trigger("change");
                </script>
            </div>
        </div>

        <div class="form-group" style="display: none;">
            <label class="col-sm-2 control-label">级别</label>
            <div class="col-sm-10">
                <input class="form-control" name="resource.levels" value="${resource.levels!0}" placeholder="级别"
                       required type="number" min="0"/>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">名称</label>
            <div class="col-sm-10">
                <input class="form-control" name="resource.name" value="${resource.name!}" placeholder="名称" required
                       autofocus/>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">顺序</label>
            <div class="col-sm-10">
                <input class="form-control" name="resource.seq" value="${resource.seq!1}" placeholder="顺序" required
                       type="number" min="1"/>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">是否在菜单中显示</label>
            <div class="col-sm-10">
                <select class="form-control" name="resource.visible" placeholder="是否在菜单中显示" required>
                    <option value="0">不显示</option>
                    <option value="1">显示</option>
                </select>
                <script>$('select[name="resource.visible"]').val('${resource.visible!0}');</script>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">访问许可编码</label>
            <div class="col-sm-10">
                <input class="form-control" name="resource.permission" value="${resource.permission!}"
                       placeholder="访问许可编码" required/>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">访问地址</label>
            <div class="col-sm-10">
                <input class="form-control" name="resource.url" value="${resource.url!}" placeholder="访问地址"/>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">描述</label>
            <div class="col-sm-10">
                <textarea class="form-control" name="resource.remark" placeholder="描述">${resource.remark!}</textarea>
            </div>
        </div>

        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="submit" class="btn btn-default">提交</button>
            </div>
        </div>
    </form>
</div>
</body>
</html>